package com.wangyadong.hobby.schedule.jobtask.ath.lesson1.stackqueue;

import com.wangyadong.hobby.schedule.jobtask.ath.common.StdIn;
import com.wangyadong.hobby.schedule.jobtask.ath.common.StdOut;

/**
 * <p>
 *
 * @author <714037465@qq.com>
 * @since 2019/4/1714:28
 **/
public class FixedCapacityStackOfString {
    private String[] a;
    private int N;

    public FixedCapacityStackOfString(int capa) {
        a = new String[capa];
    }

    public void push(String s) {
        a[N++] = s;
    }

    public String pop() {
        return a[N--];
    }

    public boolean isEmpty() {
        return size() == 0;
    }

    public int size() {
        return N;
    }

    public static void main(String[] args) {
        FixedCapacityStackOfString fixedCapacityStackOfString = new FixedCapacityStackOfString(100);
        int count = 0;
        while (!StdIn.isEmpty()) {
            String s = StdIn.readString();
            if (!s.equals("-")) {
                fixedCapacityStackOfString.push(s);
            } else if (!s.isEmpty()) {
                StdOut.println(fixedCapacityStackOfString.pop() + "  ");
            }
            System.out.println(/*StdIn.scanner.hasNext() +*/ "============" + (count++) + "--->" + s);
        }
        StdOut.println("(" + fixedCapacityStackOfString.size() + "left on the stack)");
    }
}
